<?

/***************************************************************************
Jupiter Content System @ Jupiterportal.org
 
Copyright (C) 2005-2007 Cosmin Flavius (highstrike@gmail.com)
Copyright (C) 2008-2009 George Mark (gmark@jupiterportal.org)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU 
General Public License as published by the Free Software Foundation; either version 3 of the License, 
or (at your option) any later version.

More Info About The License At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

switch($a)
{
	//-----------------------------------------------------------------
	//  Add Email
	//-----------------------------------------------------------------
	
	case 1:
	
		//-----------------------------------------------------------------
		//  Do Some Checks
		//-----------------------------------------------------------------
		
		if(!$_POST['email']) { header("location: $PHP_SELF?n=modules/contact-us&i=12"); exit; }
		if(!eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $_POST['email'])) { header("location: $PHP_SELF?n=modules/contact-us&i=13"); exit; }		
		//-----------------------------------------------------------------
		//  Strip Tags
		//-----------------------------------------------------------------
		
		$email = jcm_htmlspecialchars(trim(jcm_stripslashes(do_censor($_POST['email']))));		
		
		//-----------------------------------------------------------------
		//  Add Email
		//-----------------------------------------------------------------

		//Check email
		$emails = $db->getLine("SELECT email FROM newsletter WHERE email like '".$email."'");
		if ($emails == NULL){
			//Add email
			$db->insertRow("newsletter",array('email' => ''.$email.''));
			?>
			<table class='main' cellspacing='0' cellpadding='4'>
			 <tr class='head'>
			  <td class='head'><?echo $language['Newsletter success_title'];?></td>
			<td class='head'align='right'></td>
			 </tr>
			<tr><td class="con1" colspan='2'>
			<?php echo $language['Newsletter success'];?></td></tr></table> <?
		} else {
			?>
			<table class='main' cellspacing='0' cellpadding='4'>
			 <tr class='head'>
			  <td class='head'><?echo $language['Newsletter error_title'];?></td>
			<td class='head'align='right'></td>
			 </tr>
			<tr><td class="con1" colspan='2'>
			<?php echo $language['Newsletter error'];?></td></tr></table> 
			<?
		}
		//-----------------------------------------------------------------
		//  Redirect User
		//-----------------------------------------------------------------
		
		
	
	break;
	
	
	//-----------------------------------------------------------------
	//  Show Admin Form
	//-----------------------------------------------------------------
	case 2:
		if(isset($is_guest) || isset($is_user))
		{header("location: $PHP_SELF?i=2"); exit; }
				
	break;

	
	//-----------------------------------------------------------------
	//  Show Form
	//-----------------------------------------------------------------
	default:
	?>	
		<form method='post' action='<?= $PHP_SELF ?>?n=modules/newsletter&a=1'>
		<table class='main' cellpadding='4' cellspacing='1'>
		<col width='30%'><col width='70%'>
		<tr class='head'><td colspan='2'><?= $language['Newsletter title'] ?></td></tr>
		<tr class='con1'><td colspan='2'><?= $language['Newsletter info'] ?></td></tr>
		<tr class='bottom'><td colspan='2'><?= $language['Contact Desc1'] ?></td></tr>
		<tr class='con1'><td><span style='color:green;'><?= $language['Contact Desc2'] ?></span><td><input type='text' id='email' name='email' class='box' style='width: 100%;' onload='focus();' /></td></tr>
		<tr class='con1'><td colspan='2' align='right'><input type='submit' name='submit' value='<?= $language['Contact Desc7'] ?>' class='box' /></td></tr>
		</table>
		</form>
	<?
	break;
}
?>
